package com.sx.mongodb.service;

import com.sx.mongodb.dao.BookMongoDbDao;
import com.sx.mongodb.model.Book;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
@Slf4j
public class BookMongoDbService {

    //注入新的CURD操作类
    @Autowired
    private BookMongoDbDao bookMongoDbDao;

    /**
     * 保存对象
     *
     * @param book
     * @return
     */
    public String saveObj2(Book book) {
        book.setCreateTime(new Date());
        book.setUpdateTime(new Date());
        //调用bookMongoDbDao父类中的添加方法
        bookMongoDbDao.save(book);
        return "添加成功";
    }

    public List<Book> queryForObject(Book book){

        return bookMongoDbDao.queryList(book);
    }
}
